﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace timetableasy.Models
{
    public class EventRepository : Controller
    {
        private TimeTableDBDataContext db = new TimeTableDBDataContext();

        //Query Methods
        public IQueryable<Event> FindAllEvents()
        {
            return db.Events;
        }

        public Event GetEventById(int id)
        {
            return db.Events.SingleOrDefault(c => c.EventId == id);
        }

        //Insert/Delete Methods

        public void Add(Event Event)
        {
            db.Events.InsertOnSubmit(Event);
        }

        public void Delete(Event Event)
        {
            db.Events.DeleteOnSubmit(Event);
        }

        //Persistence

        public void Save()
        {
            db.SubmitChanges();
        }
    }
}
